//
//  BWMethod.h
//  CheTuoTuo
//
//  Created by Houge on 2021/1/20.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface BWMethod : NSObject

#pragma mark - 控制器相关
/// 获取window
+ (UIWindow *)getCurrentWindow;
/// 获取window根视图
+ (UIViewController *)getRootViewController;
/// 获取当前控制器
+ (UIViewController *)getCurrentViewController;
#pragma mark - 获取当前屏幕显示的VC
+ (UIViewController *)dc_getCurrentVC;


#pragma mark - 压缩图片
/// 压缩图片到指定文件大小 - 返回data
+ (void)compressOriginalImage:(UIImage *)image toMaxDataSizeKBytes:(CGFloat)maxLength complete:(void(^)(NSData *imageData))complete;

/// 压缩图片到指定文件大小 - 返回image
+ (void)compressOriginalImageToImage:(UIImage *)image toMaxDataSizeKBytes:(CGFloat)maxLength complete:(void (^)(UIImage *resultImage))complete;


#pragma mark - 视频压缩
/// 压缩视频
+ (void)compressVideo:(NSURL *)videoUrl
    withVideoSettings:(NSDictionary *)videoSettings
        AudioSettings:(NSDictionary *)audioSettings
             fileType:(AVFileType)fileType
             complete:(void (^)(NSURL * _Nullable, NSError * _Nullable))complete;

/// 指定音视频的压缩码率，profile，帧率等关键参数信息，这些参数可以根据要求自行更改
+ (NSDictionary *)performanceVideoSettings;
+ (NSDictionary *)performanceAudioSettings;


#pragma mark - 时间相关
/// 字符串->时间
+ (NSDate *)stringToDate:(NSString *)dateStr dateFormat:(nullable NSString *)format;

/// 时间->字符串
+ (NSString *)dateToString:(NSDate *)date dateFormat:(nullable NSString *)format;

/// 解析 时间戳
/// 返回NSDate
+ (NSDate *)timestampToDate:(NSInteger)timestamp;

/// 解析 时间戳
/// 返回NSString
+ (NSString *)timestampToDateString:(NSInteger)timestamp dateFormat:(nullable NSString *)format;

/// 字符串转时间戳
+ (NSTimeInterval)dateStringToTimestamp:(NSString *)dateString;

/// 转换成 时:分:秒
+ (NSString *)timeFormatted:(NSInteger)totalSeconds;

/// 大于1小时, 转换成 00:00:00
/// 小于1小时, 转换成 00:00
+ (NSString *)timeFormattedBetter:(NSInteger)totalSeconds;

/// 转换成 00:00
+ (NSString *)timeFormattedToMinuteSecond:(NSInteger)totalSeconds;
/// 转换成 分:秒
+ (NSString *)timeFormattedToChineseMinuteSecond:(NSInteger)totalSeconds;

/// 转换日期为昨天今天
+ (NSString *)translateDateWithDateString:(NSString *)dateStr;


#pragma mark - 路径相关
/// 获取Caches目录路径
+ (NSString *)getCachesPath;

/// 获取path路径下文件夹的大小
+ (NSString *)getCacheSizeWithFilePath:(NSString *)path;

/// 转换数据大小, 转换为 M/KB/B
+ (NSString *)translateDataSize:(NSInteger)totalSize;

/// 清除path路径下文件夹的缓存
+ (BOOL)clearCacheWithFilePath:(NSString *)path;


#pragma mark - 文件大小
/// 获取单个文件的大小
+ (long long)fileSizeAtPath:(NSString *)filePath;

/// 获取文件夹的大小
+ (float)folderSizeAtPath:(NSString *)folderPath;


#pragma mark - 类型转换
/// NSString转NSDictionary
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;

/// NSString转NSArray dictionary
+ (NSArray *)dictArrayWithJsonString:(NSString *)jsonString;

/// NSObject转NSString
+ (NSString *)objectToJsonString:(id)object;

/// Unicode转中文
+ (NSString *)transformUnicodeString:(NSString *)unicodeStr;

/// 转json
+ (NSString*)dictionaryToJson:(NSDictionary *)dic;

/// 将HTML字符串转化为NSAttributedString富文本字符串
/// 解决 "<" 变成 "&lt;" 的问题
+ (NSString *)attributedStringWithHTMLString:(NSString *)htmlString;


#pragma mark - 手机号格式
+ (BOOL)verifyPhoneNumber:(NSString*)phone;

+ (BOOL)validateEmail:(NSString *)email;


#pragma mark - 进制转换

/// 字符串转十六进制
+ (NSString *)hexStringFromString:(NSString *)string;

/// 十六进制转换为普通字符串
+ (NSString *)stringFromHexString:(NSString *)hexString;

#pragma mark - 手机型号
/// 获取手机型号
+ (NSString *)getPhoneType;
/// 只返回数字
+ (NSInteger)getPhoneTypeNumber;

@end

NS_ASSUME_NONNULL_END
